package com.wx.mybatis.controller;

import com.wx.mybatis.entity.UserInfo;
import com.wx.mybatis.entity2.UserInfo2;
import com.wx.mybatis.service.UserInfoService;
import com.wx.mybatis.service2.UserInfoService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ClassName TestUserInfoController
 * @Author wx
 * @Description 用户测试Controller
 * @Date 2018-12-27-21:45
 */
@RestController
@RequestMapping(value = "/test")
public class TestUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private UserInfoService2 userInfoService2;

    /**
     * @methodName: addUserInfo
     * @author: wx
     * @description: 测试单库插入数据
     * @param
     * @date: 2018/12/27
     * @return: void
     */
    @PostMapping(value = "/addUserInfo")
    public void addUserInfo() {
        UserInfo userInfo = new UserInfo();
        userInfo.setName("wx_mybatis");
        userInfo.setJobNumber("wx_mybatis_000");
        userInfo.setCreateTime(new Date());
        userInfoService.save(userInfo);
    }

    /**
     * @methodName: testMoreDataSource
     * @author: wx
     * @description: 测试多库插入数据
     * @param
     * @date: 2018/12/27
     * @return: void
     */
    @PostMapping(value = "/testMoreDataSource")
    public void testMoreDataSource() {
        UserInfo userInfo = new UserInfo();
        userInfo.setName("wx_mybatis_db_1");
        userInfo.setJobNumber("wx_mybatis_db_1_0001");
        userInfo.setCreateTime(new Date());
        userInfoService.save(userInfo);

        UserInfo2 userInfo2 = new UserInfo2();
        userInfo2.setName("wx_mybatis_db_2");
        userInfo2.setJobNumber("wx_mybatis_db_2_0001");
        userInfo2.setCreateTime(new Date());
        userInfoService2.save(userInfo2);
    }
}
